﻿
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="static/img/favicon.png">

    <title>INX Access Control System</title>
    <link href="static/css/bootstrap.css" rel="stylesheet">
	<script src="static/js/jquery-1.11.1.min.js" type="text/javascript"></script>
	<script src="static/js/bootstrap.min.js"></script>
	<style type="text/css">
		.div{width:80%;margin-left: auto;margin-right: auto;}
		.login{width:35%;margin-left: auto;margin-right: auto;}
		.modal-60{width:60%;margin-left: auto;margin-right: auto;}
		.myModal {width: 80%;margin: -250px 0 0 -450px; }
		.text{text-align:center; font-size:30px;font-weight:bold;height:30px;line-height:30px;}
	</style>
  </head>
  <body>
      <div class="navbar navbar-inverse div">
          <div class="navbar-header">
            <a class="navbar-brand" href="/">INX Access Control System</a>
        </div>
			<div class="pull-right">
		  	{% if status=="1" %}
				<a class="navbar-text" id="logout" data-toggle="modal" href="/logout">歡迎您,{{ user }}</a>
			{% else %}
				<a class="navbar-text pull-right" id="status" data-toggle="modal" href="#login">Login</a>
			{% end %}
		  </div>
      </div>
		  {% if status=='1' %}
			<div class="login">
			<h2 class="form-signin-heading">{{ location }} ACS 授權管理：</h2>
			<table id="main" class="table table-striped table-bordered table-hover">
			<tr>
			<td>ACS登入密碼：</td>
			<td><input type="password" id="pwd1" class="form-control" placeholder="Password"></td>
			</tr>
			<tr>
			<td>確認輸入：</td>
			<td><input type="password" id="pwd2" class="form-control" placeholder="Password"></td>
			<td><button class="btn btn-lg btn-primary btn-block" type="button" id="subedit">提交</button></td>
			</tr>
			</table>
			</div>
			
			<div class="login">
			<h2 class="form-signin-heading">權限交接：</h2>
			<table id="main" class="table table-striped table-bordered table-hover">
			<tr>
			<td>將你的權限交接給：</td>
			<td><input type="text" id="per" class="form-control" placeholder="User Name"></td>
			<td><button class="btn btn-lg btn-primary btn-block" type="button" id="perto">確定？</button></td>
			</tr>
			</table>
			</div>
			
			{% end %}
	<!-- Login-->
		<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="loginmodal" aria-hidden="true">
		<div class="modal-dialog login">
			<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="form-signin-heading">Please sign in</h4>
			</div>
			<div class="modal-body">
				<div class="container modal-60 div">
					<input type="text" id="username" class="form-control" placeholder="User Name" required autofocus>
					<input type="password" id="password" class="form-control" placeholder="Password" required>
					<button class="btn btn-lg btn-primary btn-block" type="button" id="loginpost">Sign in</button>
				</div>
			</div>
			</div>
		</div>
		</div>

<script>
if ({{ status }}=='0')
	{
	$("#login").modal();
	}
else{
	if ({{ status }}=='404')
		{
		alert("你無權登入！")
		}
}

$("#subedit").click(
	function(){
		if ($("#pwd1").val() != $("#pwd2").val() || $("#pwd2").val()==''|| $("#pwd1").val()=='')
			{
			alert("你的輸入有誤：您輸入了空值或者兩次輸入不一致！")
			}
		else
			{
			$.post("pwdchange",{
				password:$("#pwd2").val(),
				location:"{{ location }}",
				},function(dat){
					if (dat=="000"){alert("密碼修改失敗，若再次嘗試仍然無法修改，請聯繫系統管理員")}
					else {
						alert("密碼修改成功,請在Client使用新密碼登入！")
						}
					})
			}
		}
	)

$("#perto").click(
	function(){
		if ($("#per").val()=='')
			{
			alert("你的輸入有誤：輸入不能為空！")
			}
		else
			{
			if (confirm("確定要將權限交接給：" + $("#per").val() + "?交接后你將登出，且無權再登入本系統！")){
				
				$.post("perto",{
					user:$("#per").val(),
					location:"{{ location }}",
					loginuser:"{{ user }}",
					},function(dat){
						if (dat=="000"){alert("異動失敗，若再次嘗試仍然無法修改，請聯繫系統管理員")}
						else {
							alert("異動成功,你即將登出！");
							window.location="/logout";
							}
						})
			}
			}
		}
	)

$("#loginpost").click(
		function(){
			if($("#username").val() =="" || $("#password").val() ==""){
				alert("用戶名或密碼不能為空！");}
			else {
				if ({{ status }}=="0"){
					$("#login").modal("hide");
					$.post("login",{
						username:$("#username").val(),
						password:$("#password").val(),},
						function(user){
							if(user=="0"){alert("登錄失敗：用戶名或密碼有誤！");}
							else {
								if(user=="404"){
									alert ("你無權使用！");
									location.reload();
								}}
								location.reload();
					
						}).error(function(){alert("請求失敗，請聯繫系統管理員！");})
				} else {alert("您已經登入，請勿重複操作！");}}
})
$("#logout").click(
	function(){
	if  (confirm("確定要登出？")){
		return true;
	}
	else {
		return false;
	}

	})
</script>
  </body>
</html>
